#ifndef __SYSFIFO_H
#define __SYSFIFO_H

#ifdef __cplusplus
 extern "C" {
#endif
	 
#include "System.h"

typedef enum {
	FifoOK				= 0,
	FifoErrSizeIllegal	= 1,
	FifoErrIsEmpty		= 2,
	FifoErrIsFull		= 3,
}FifoSta_E;

typedef struct tagFifo
{
    volatile UINT32   wIdx; /* counter for FIFO input, inc in ISR only */
    volatile UINT32   rIdx; /* counter for FIFO output, inc in MAIN only */
    UINT32            size;            /* FIFO buffer size */
    UINT32            mask;            /* Mask to extract buffer index from counters */
}Fifo_T,*pFifo_T;

UINT32 Fifo_Init(pFifo_T _fifo,const UINT32 _size);
UINT32 Fifo_IsEmpty(pFifo_T _fifo);
UINT32 Fifo_IsFull(pFifo_T _fifo);
UINT32 Fifo_GetLen(pFifo_T _fifo,UINT32 *_len);
UINT32 Fifo_Get(pFifo_T _fifo, UINT32 *_index);
UINT32 Fifo_Put(pFifo_T _fifo, UINT32 *_index);

typedef struct{
    Fifo_T	fifo;
	UINT8   *buffer;
}FifoBuf_T;

UINT8 	FIFO_InserData(FifoBuf_T *_buf,UINT8 _data);
UINT32	FIFO_GetLen(FifoBuf_T *_buf);
UINT8 	FIFO_GetData(FifoBuf_T *_buf,UINT8 *_data);
UINT8 	FIFO_GetPosData(FifoBuf_T *_buf,UINT32 _pos);


#ifdef __cplusplus
}
#endif
#endif
